<!-- <?php include "from.php" ?> -->

<?php

//trait的优先顺序是当前类中的方法会覆盖 trait 方法，而 trait 方法又覆盖了基类中的方法
//PHP高手之路：https://phper.shujuwajue.com/
abstract class Person
{
    abstract public function init();
    abstract public function login();
    abstract public function logout();
}
interface PersonBehavior
{
    public function logInfo();
}
class User extends Person implements PersonBehavior
{
    const VERSION = "1.0.0";
    public $name;
    public $age;

    public function init()
    {
        echo "Init";
    }

    public function login()
    {
        echo "Login";
        return false;
    }

    public function logout()
    {
    }
    public function logInfo()
    {
        echo "Name: " . $this->name . "<br>";
        echo "Age: " . $this->age . "<br>";
    }
}
class AdminUser extends User
{
    public function login()
    {
        return true;
    }
}
echo User::VERSION;
$user = new User();
$user->name = "John";
$user->age = 20;
// 将对象序列化为字符串后保存到文件
file_put_contents("user.txt", serialize($user));
// 从文件读取对象字符串反序列化为对象
$userObj = file_get_contents("user.txt");
$user = unserialize($userObj);
$user->logInfo();


// 判断某个对象实例是否实现了某个接口或者是某个父类/抽象类的子类实例
var_dump($user instanceof PersonBehavior);

define("SDKVERSION", "1.0.0");
// 字符串
$name = "John";
$adress = "New York";
// 拼接
$info = $name . $adress;
echo "Hello: $info";
echo is_string($info);

//数组常用方法
$loves = array("cat", "dog", "food");

//array_push()：添加元素到数组末尾。
array_push($loves, "water");
//array_pop()：删除数组末尾元素。
array_pop($loves);
//array_unshift()：添加元素到数组开头。
array_unshift($loves, "hello");
//array_shift()：删除数组开头元素。
array_shift($loves);
//结果：删除了数组开头的元素hello。

$simArr = ["name" => "wangcl", "age" => 20, "sex" => "man"];
$simArr = ["name" => "wangcl", "age" => 20, "sex" => "man"];

// 对象数组（key-value）
$likes = array("type" => "dog", "name" => "Ject", "age" => 10);
echo "I love " . $loves[0] . ", " . $loves[1] . " and " . $loves[2];
var_dump($name);
var_dump($_SERVER["HTTP_HOST"] ?? "");
var_dump($_GET ?? "");
//当前运行脚本所在的服务器的 IP 地址。
//echo $_SERVER["SERVER_ADDR"];
//当前运行脚本所在的服务器的主机名
//echo $_SERVER["HTTP_HOST"];
